var runTest = {
    /**
     * 单个用例调用请求的方法
     * 新增和修改测试用例的页面发起的一次请求
     */
    runTestCallByCase: function () {
        oKeyValueUtil.writeParam();
        var interfaceId = $("#interfaceId").val();
        var paramValue = $("#paramValue").val();
        var paramKeyValue = $("#paramKeyValue").val();
        var paramType = $("#paramType").val();
        $.ajax({
            url: "/runTestController/runTestCallByCase",
            type: "post",
            dataType: "json",
            async: true,
            data: {
                interfaceId: interfaceId,
                paramValue: paramValue,
                paramKeyValue: paramKeyValue,
                paramType: paramType
            },
            beforeSend: function () {
                $("#wait").show();
                $("#runButton").attr("disabled", "disabled")
            },
            success: function (result) {
                $("#wait").hide();
                $("#runButton").removeAttr("disabled");
                if (result.success) {
                    var expectResult = result.obj;
                    testCase.initExpectResult(expectResult);
                } else {
                    testCase.initExpectResult(result);
                }
            }, error: function (result) {
                $("#wait").hide();
                $("#runButton").removeAttr("disabled");
            }
        })
    },

    /**
     * 批量运行接口
     * @return list
     */
    runTestByInterface: function (interfaceIds) {
        var url = "/testPlanController/buildTempPlan";
        $.ajax({
            url: url,
            type: "post",
            traditional: true,
            data: {
                interfaceIds: interfaceIds,
                projectId: projectId
            },
            success: function (result) {
                if (result.success) {
                    var url = "/runTestController/runTestByBuildId?buildTestId=" + result.obj;
                    window.location.href = url;
                } else {
                    toastr.error(result.msg)
                }
            }
        })
    },
    /**
     * 批量运行测试用例
     * @return list
     */
    runTestByCase: function (interfaceId, caseIds) {
        var url = "/testPlanController/buildTempPlanTestCase";
        $.ajax({
            type: "post",
            url: url,
            traditional: true,
            data: {
                interfaceId: interfaceId,
                caseIds: caseIds,
                projectId: projectId
            },
            beforeSend: function () {

            },
            success: function (result) {
                if (result.success) {
                    var url = "/runTestController/runTestByBuildId?buildTestId=" + result.obj;
                    window.location.href = url;
                } else {
                    toastr.error(result.msg)
                }
            }
        });
    },
    runTestPlan: function (testPlanId) {
        var testPlanId = $("#testPlanId").val();
        var testPlanName = $("#topTestPlanName").text();
        $.ajax({
            url: "/testPlanController/buildPlan",
            type: "post",
            dataType: "json",
            traditional: true,
            async: true,
            data: {
                testPlanName: testPlanName,
                testPlanId: testPlanId,
                projectId: projectId
            }, success: function (result) {
                if (result.success) {
                    var url = "/runTestController/runTestByBuildId?buildTestId=" + result.obj;
                    window.location.href = url;
                } else {
                    toastr.error(result.msg)
                }
            }
        })
    },
    stopRun: function (testTaskId, goPage, buildTestId) {
        var url = "/TestTaskController/stopRun";
        $.ajax({
            url: url,
            type: "post",
            dataType: "json",
            traditional: true,
            async: true,
            data: {
                testTaskId: testTaskId,
                projectId: projectId,
                buildTestId: buildTestId
            }, success: function (result) {
                if (result.success) {
                    if (goPage != "goPage") {
                        performanceTask.run(testTaskId);
                    } else {
                        performanceTask.goBackPage();
                    }
                } else {
                    parent.$.messager.alert('提示:', result.msg, 'info');
                }
            }
        })
    }
}


